package com.chen.day01_base;


import com.chen.annotation.DataSource;
import com.chen.annotation.Excel;
import com.chen.domain.SysNotice;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;

/**
 * 反映测试
 *
 * @author chenyj
 * @date 2023/07/17
 */
@Slf4j
public class ReflectTest {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<?> aClass1 = Class.forName(   "com.chen.domain.SysNotice");
        Class<?> aClass2 = SysNotice.class;
        Class<?> aClass3 = new SysNotice().getClass();
        System.out.println(aClass1 == aClass3);
        System.out.println("-----------------------");
        DataSource annotation1 = aClass2.getAnnotation(DataSource.class);
        System.out.println(annotation1.toString());
        System.out.println(annotation1.value());
        //拿到所有属性
        Field[] declaredFields = aClass2.getDeclaredFields();
        System.out.println(Arrays.toString(declaredFields));
        System.out.println("====================");
        for (Field declaredField : declaredFields) {
            //输出静态属性
            if (Modifier.isStatic(declaredField.getModifiers())) {
                System.out.println(declaredField.getName());
            }
            if (declaredField.isAnnotationPresent(Excel.class)) {
                Excel annotation = declaredField.getAnnotation(Excel.class);
                System.out.println(annotation.height() + " " + declaredField);
            }
        }
        System.out.println("22222222222222222222222");
        System.out.println(aClass2.getSuperclass());
    }
}
